<template>
  <a-card :bordered="false"  :style="{ marginTop: '12px',height:'395px' }">
    <span slot="title"> <a-icon type="tags" style="color:#3393FC;margin-right:5px" theme="filled"/>系统公告</span>
    <a slot="extra" @click="loadMore('notice')">更多</a>
    <template v-if="formData.length>0">
      <a-list itemLayout="horizontal" :dataSource="formData">
        <a-list-item @click="showAnnouncement(item)" slot="renderItem" :key="index" slot-scope="item, index">
          <a-list-item-meta>
            <a slot="title" href="#" :style="{color:item.readFlag=='0'?'':'#d2d2d2'}">{{item.titile}}</a>
          </a-list-item-meta>
          <div>{{item.sendTime}}</div>
        </a-list-item>
      </a-list>
    </template>
    <template v-else>
      <a-empty />
    </template>
    <dynamic-notice ref="showDynamNotice" :path="openPath" :formData="formDataNotice"/>
    <show-announcement ref="ShowAnnouncement" @ok="modalFormOk"></show-announcement>
  </a-card>
</template>

<script>
  import { putAction } from '@/api/manage'
  import DynamicNotice from '@/components/tools/DynamicNotice'
  import ShowAnnouncement from '@/components/tools/ShowAnnouncement'
  import { getUserNoticeInfo } from '@/api/api'

  export default {
    name: 'EoaCmsUserNotice',
    components: {
      DynamicNotice,
      ShowAnnouncement
    },
    data () {
      return {
        formDataNotice: {},
        openPath: '',
      }
    },
    props: ['formData'],
    methods: {
      loadMore(type){
        this.$router.push({ path: '/isps/userAnnouncement'})
      },
      showAnnouncement(record){
        putAction('/sys/sysAnnouncementSend/editByAnntIdAndUserId',{anntId:record.anntId}).then((res)=> {
          if (res.success) {
            getUserNoticeInfo({ pageNo: 1, pageSize: 5 }).then((res) => {
              if (res.success) {
                this.userNotice = res.result.records;
                console.log("this.userNotice::", this.userNotice)
              }
            })
          }
        });
        if(record.openType==='component'){
          this.openPath = record.openPage;
          this.formDataNotice = {id:record.busId};
          this.$refs.showDynamNotice.detail(record.openPage);
        }else{
          this.$refs.ShowAnnouncement.detail(record);
        }
      },
      modalFormOk(){
        this.initSiteInfo();
      },
      initSiteInfo () {
        var _this=this;
        getUserNoticeInfo({pageNo:1,pageSize:5}).then((res)=>{
          if(res.success){
            _this.formData=res.result.records;
          }
        })
      },
    }
  }
</script>

<style scoped>

</style>